<?php
/**
 * User: liwentao
 * Date: 7/20/15
 * Time: 17:34
 */

?>
<script>
      function pk_outpatient_prescription_del(){
      	if($('#del_reason').val() == ''){
      		alert('废除原因不能为空');
      		return false;
      	}
        $.ajax({
            type: 'POST',
            url: '<?php echo CController::createUrl('prescription/delprescription') ;?>',
            data: {del_reason:$('#del_reason').val(),pk_outpatient_prescription_id:'<?php echo $pk_outpatient_prescription_id; ?>'},
            success: function(data){
                if(data.status==0){
                    var maintab = $('#main-tab');
                    alert('废除成功');
                    var tab = maintab.tabs('getSelected');

                    tab.panel('refresh', "<?php echo Yii::app()->request->baseUrl; ?>/index.php?r=prescription/findPerscription&pk_outpatient_prescription_id=<?php echo $prescriptions->pk_outpatient_prescription_id;?>&pk_outpatient_id=<?php echo $prescriptions->fk_outpatient_id?>");

                    $('#prescription').treegrid('load',{
                     url: "<?php echo CController::createUrl('prescription/getprescriptions',array('pk_outpatient_id'=>$prescriptions->fk_outpatient_id)) ;?>"
                    });
                    $('#pk_outpatient_prescription_del').form('clear');
                    $('#win_outpatient_prescription').window('close');
                }else{
                    alert('废除失败,请重试');
                }
            },
            dataType: 'json'
        });
    }
</script>
<div id="win_outpatient_prescription" class="easyui-window" closed="true"  style="width:300px;height:180px;">
<form style="padding:10px 20px 10px 40px;" id="pk_outpatient_prescription_del">
    <p>废除原因: 
    <input type="text" name="del_reason" id="del_reason">
    <input type="hidden" name="pk_outpatient_prescription_id" value = "<?php echo $pk_outpatient_prescription_id; ?>"></p>

    <div style="padding:5px;text-align:center;">
        <a href="#" class="easyui-linkbutton" icon="icon-ok" onclick="pk_outpatient_prescription_del();">确定</a>
        <a href="#" class="easyui-linkbutton" icon="icon-cancel" onclick = "javascript:$('#win_outpatient_prescription').window('close')">取消</a>
    </div>
</form>
</div>
<div class="easyui-layout" data-options="border:false,fit:true">
    <div data-options="region:'center',border:false" style="padding:5px;background:#eee;width:840px;">

		<div class="easyui-panel" data-options="border:false" style="padding:5px;">
		    <div class="easyui-panel" data-options="border:false" style="width:100%;height:36px;background:#fafafa;margin-bottom: 10px;padding-top:5px;padding-left: 5px;">

		    <?php if($prescriptions->invalid ==1):?>

			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="$('#win_outpatient_prescription').window('open');">废除处方</a>

			<?php endif?>

			<?php if($prescriptions->invalid ==2):?>

			<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel',disabled:true">已废除处方</a>

			<?php endif?>

		        
		    </div>
		    <div class="easyui-panel" data-options="border:false" style="width:100%;height:30px;background:#fafafa;margin-bottom: 5px;">
		        <div class="easyui-layout" data-options="border:false,fit:true">
		            <div data-options="region:'west',border:false" style="width:33%;padding:5px;">医生姓名：&nbsp;&nbsp;<?php echo Yii::app()->session['true_name'];?></div>
		            <div data-options="region:'center',border:false" style="padding:5px;">患者健康号：&nbsp;&nbsp;<?php echo $outpatient['username'];?></div>
		            <div data-options="region:'east',border:false" style="width:33%;padding:5px;">时间：&nbsp;&nbsp;<?php echo date('Y年m月d日')?>&nbsp;&nbsp;<?php echo date('H:s')?></div>
		        </div>
		    </div>
		    <form id="form-prescription" method="post">
		        <input type="hidden" name="fk_outpatient_id" value="<?php echo $pk_outpatient_id; ?>"/>
		        <div class="easyui-panel" data-options="border:true,title:'患者信息'" style="width:100%;padding:5px;background:#fafafa;margin-bottom: 10px;">
		            <div class="table-patient">
		                <table style="width:100%;">
		                    <tbody>
		                    <tr>
		                        <th align="right">真实姓名：</th>
		                        <td><?php echo $outpatient['true_name'];?></td>
		                        <th align="right">性别：</th>
		                        <td>
		                            <?php
		                                if($outpatient['gender']==1){
		                                    echo '男';
		                                }else if($outpatient['gender']==2){
		                                    echo '女';
		                                }else {
		                                    echo '保密';
		                                }
		                            ?>
		                        </td>
		                        <th align="right">电话：</th>
		                        <?php if($outpatient['phone']!=NULL):?>
		                            <td><?php echo $outpatient['phone'];?></td>
		                        <?php else: ?>
		                            <td><?php echo $outpatient['phone'];?></td>
		                        <?php endif; ?>
		                    </tr>
		                    <tr>
		                        <th align="right">生日：</th>
		                        <td><?php echo $outpatient['dob'];?></td>
		                        <th align="right">年龄：</th>
		                        <?php
		                            $age = age($outpatient['dob']);
		                        ?>
		                        <td><?php echo $age;?></td>
		                        <th align="right">职业：</th>
		                        <td><?php echo $outpatient['occupation'];?></td>
		                    </tr>
		                    <tr>
		                        <th align="right">住址：</th>
		                        <td colspan="5"><?php echo $outpatientLocation['address'];?></td>
		                    </tr>
		                    <tr>
		                        <th align="right">体重：</th>
		                        <td><?php echo $outpatient['weight'];?>&nbsp;kg</td>
		                        <th align="right">身高：</th>
		                        <td><?php echo $outpatient['stature'];?>&nbsp;cm</td>
		                        <th align="right">民族：</th>
		                        <td><?php echo $outpatient['occupation'];?></td>
		                    </tr>
		                    <tr>
		                        <th align="right">饮酒：</th>
		                        <td>
		                         <?php
		                            if($outpatient['alcohol']==1){
		                                echo '从不';
		                            }else if($outpatient['alcohol']==2){
		                                echo '很少';
		                            }else if($outpatient['alcohol']==3){
		                                echo '有时';
		                            }else if($outpatient['alcohol']==4){
		                                echo '经常';
		                            }else if($outpatient['alcohol']==5){
		                                echo '总是';
		                            }else {
		                                echo '其他';
		                            }
		                        ?>
		                        </td>
		                        <th align="right">吸烟：</th>
		                        <td><?php if($outpatient['smoke']==NULL) echo '0'; else echo $outpatient['smoke']; ?> 支/天</td>
		                        <th align="right">血型：</th>
		                        <td>
		                        	<?php
		                            if($outpatient['blood_type']==1){
		                                echo 'A';
		                            }else if($outpatient['blood_type']==2){
		                                echo 'B';
		                            }else if($outpatient['blood_type']==3){
		                                echo 'AB';
		                            }else if($outpatient['blood_type']==4){
		                                echo 'O';
		                            }else {
		                                echo '其他';
		                            }
		                        ?>
		                        </td>
		                    </tr>
		                    <tr>
		                        <th align="right" >过敏史：</th>
		                        <td colspan="5"><?php echo $outpatient['allergy'];?></td>
		                    </tr>
		                    </tbody>
		                </table>
		            </div>
		        </div>
		        <div id="prescription-tab" class="easyui-tabs" data-options="border:true,plain:true" style="height:415px;">
		            <div title="处方" data-options="iconCls:'icon-prescription'" style="padding:5px;">
		                <table cellpadding="5" style="width:100%;">
		                    <tr>
		                        <td style="width:100px;">诊断内容:</td>
		                        <td><?php echo $prescriptions['diagnosis']?></td>
		                    </tr>
		                    <tr>
		                        <td style="width:100px;">医生嘱咐:</td>
		                        <td><?php echo $prescriptions['exhort']?></td>
		                    </tr>
		                    <tr style="background-color: #F7F7F7">
		                        <td>用药:</td>
		                        <td><table title="" style="width:700px;height:250px"
									data-options="singleSelect:true,collapsible:true,url:'datagrid_data1.json',method:'get'">
									<thead>
										<?php $medicine_arr = json_decode($prescriptions['medicine'],true) ?>
										<tr>
											<th style="width:120px">药品名称</th>
											<th style="width:80px">单次用量</th>
											<th style="width:90px">用发</th>
											<th style="width:120px">备注</th>
											<th style="width:60px">频度</th>
											<th style="width:60px">天数</th>
											<th style="width:60px">总量</th>
											<th style="width:60px">价格</th>	
										</tr>
										<?php if($medicine_arr){foreach ($medicine_arr as $key => $value) {

											echo '<tr><td>'.$value['medicine_name'].'</td><td>'.$value['yongliang'].'</td><td>'.$value['yongfa'].'</td><td>'.$value['beizhu'].'</td><td>'.$value['pindu'].'</td><td>'.$value['day'].'</td><td>'.$value['count'].'</td><td>'.$value['price'].'</td></tr>';
											
										}}?>
									</thead>
									</table>
								</td>
		                    </tr>
		                </table>
		            </div>
		        </div>
		    </form>
		</div>


    </div>
</div>
